class Solution
{
public:
    vector<int> sumEvenAfterQueries(vector<int> &nums, vector<vector<int>> &queries)
    {
        int evenSum = 0;
        for (int num : nums)
        {
            if (!(num & 1))
            {
                evenSum += num;
            }
        }
        vector<int> ans;
        ans.reserve(queries.size());
        for (auto &query : queries)
        {
            int val = query[0];
            int index = query[1];
            if ((nums[index] & 1) && (val & 1))
            {
                evenSum += nums[index] + val;
            }
            else if (!(nums[index] & 1) && !(val & 1))
            {
                evenSum += val;
            }
            else if (!(nums[index] & 1) && (val & 1))
            {
                evenSum -= nums[index];
            }
            ans.push_back(evenSum);
            nums[index] += val;
        }
        return ans;
    }
};